package calorie.com.calorie.contact;

import android.content.Context;


import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.SPUtils;
import com.lxh.baselibray.util.ToastUtils;


import calorie.com.calorie.api.ApiService;
import calorie.com.calorie.constant.Constant;
import calorie.com.calorie.request.ApplyLevelRequest;
import calorie.com.calorie.response.ApplyLevelResponce;
import calorie.com.calorie.response.GradeResponce;
import retrofit2.Call;
import retrofit2.Response;

public class GradeContact {
    public static class  GradePresent extends BasePresent<IGradeView>{
        public void queryGradeMsg(Context context){
            ApiService service= ServiceGenerator.createService(ApiService.class);
            int userId= SPUtils.getInt(Constant.USER_ID,-1,context);
            service.queryGradeMsg(userId).enqueue(new NetCallBack<GradeResponce>() {
                @Override
                public void onSuccess(Call<GradeResponce> call, Response<GradeResponce> response) {
                    if (getView()!=null){
                        getView().getGradeMsgData(response);
                    }
                }

                @Override
                public void onFailed() {
                   // ToastUtils.showLongToast(context,"网络请求异常");
                }
            });
        }
        public void applyLevel(Context context,String remarks){
            ApiService service= ServiceGenerator.createService(ApiService.class);
            int userId= SPUtils.getInt(Constant.USER_ID,-1,context);
            ApplyLevelRequest request=new ApplyLevelRequest(userId,remarks);
            service.applyLevel(request).enqueue(new NetCallBack<ApplyLevelResponce>() {
                @Override
                public void onSuccess(Call<ApplyLevelResponce> call, Response<ApplyLevelResponce> response) {
                    if (getView()!=null){
                        getView().getApplyLevelData(response);
                    }
                }

                @Override
                public void onFailed() {
                   // ToastUtils.showLongToast(context,"网络请求异常");
                }
            });
        }
    }

    public interface IGradeView extends IBaseView{
        void getGradeMsgData(Response<GradeResponce> response);
        void getApplyLevelData(Response<ApplyLevelResponce> response);
    }
}
